//
//  TextMessageTableViewCell.m
//  LeanMessageDemo
//
//  Created by WuJun on 8/24/15.
//  Copyright (c) 2015 LeanCloud. All rights reserved.
//

#import "LeftTextMessageTableViewCell.h"

@implementation LeftTextMessageTableViewCell

-(void)setTextMessage:(AVIMTextMessage *)textMessage{
    
    [super setTextMessage:textMessage];
 // 显示文本消息的内容setAttributedText
    [self.textMessageContentTextView setAttributedText:[[NSMutableAttributedString alloc] initWithString:textMessage.text]];
  
  CGRect frame = [self bubbleView:textMessage.text];
  CGRect labelFrame = self.textMessageContentTextView.frame;
    labelFrame.size = frame.size;
    self.textMessageContentTextView.frame = labelFrame;
    if (frame.size.width < 200) {
            NSArray* constrains = self.self.textMessageContentTextView.constraints;
            for (NSLayoutConstraint* constraint in constrains) {
                if (constraint.firstAttribute == NSLayoutAttributeWidth) {
                    constraint.constant = frame.size.width + 10;
                }
            }
    }

    [self layoutIfNeeded];
}
- (CGRect)bubbleView:(NSString *)text{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
    CGRect frame = [text boundingRectWithSize:CGSizeMake(200, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame;
    
}

- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
